package com.ykdl.member.kid.adapters;

import java.util.ArrayList;

import com.ykdl.member.kid.R;
import com.ykdl.member.kid.adapters.MyLetterAdapter.ViewHolder;
import com.ykdl.member.kid.beans.PraiseBean;
import com.ykdl.member.kid.image.ImageOptions;
import com.ykdl.member.kid.image.ImageOptionsFactory;
import com.ykdl.member.kid.util.DateUtil;
import com.ykdl.member.kid.widget.AsyncImageView;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class PraisesMeAdapters extends BaseAdapter{
	
	private Activity mContext ;
	private ArrayList<PraiseBean>  list;
	private String TAG ;
	 private ImageOptions options=null ;
	public PraisesMeAdapters(Activity context, String tag){
		this.mContext = context;
		TAG = tag ;
		options = ImageOptionsFactory.getBigPortraitOptions(context);
	}
	public void setlist(ArrayList<PraiseBean>  list) {
		this.list= list ;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if (list != null) {
			return list.size();
		} else {
			return 0;
		}
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		if (getCount() != 0) {
			return list.get(position-1);
		} else {
			return null;
		}
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null ;
		if (convertView==null) {
			convertView = RelativeLayout.inflate(mContext,
					R.layout.praisesmeadapter_item, null);
			holder = new ViewHolder();
			 holder.user_head =  (AsyncImageView) convertView.findViewById(R.id.user_head);
			 holder.user_name=  (TextView) convertView.findViewById(R.id.user_name);
			 holder.user_grade=  (TextView) convertView.findViewById(R.id.grade);
			 holder.user_time=  (TextView) convertView.findViewById(R.id.user_time);
			 holder.user_age=  (TextView) convertView.findViewById(R.id.user_age);
			 holder.user_address=  (TextView) convertView.findViewById(R.id.user_address);
			 holder.group_name=  (TextView) convertView.findViewById(R.id.group_name);
			 holder.reply_count=  (TextView) convertView.findViewById(R.id.reply_count);
			 holder.topic_reanser_name=  (TextView) convertView.findViewById(R.id.topic_reanser_name);
			 holder.topic_reanser_content=  (TextView) convertView.findViewById(R.id.topic_reanser_content);
			 convertView.setTag(holder);
		}else {
			holder = (ViewHolder)convertView.getTag();
		}
		if (list.get(position).getActor().getAvatar_file_meta()!=null) {
			String url = list.get(position).getActor().getAvatar_file_meta().getDownload_urls().getSmal().getUrl();
			holder.user_head.setUrl(TAG, url, options) ;
		}
		holder.user_name.setText(list.get(position).getActor().getDisplay_name());
		 holder.user_grade.setText(list.get(position).getActor().getLevel()+"");
		 holder.user_time.setText(DateUtil.gettopicDate(list.get(position).getCreated_time()));
		 if (list.get(position).getActor().getBaby_profile()!=null) {
			 String strAge = DateUtil.getBabyAge((long) list.get(position).getActor().getBaby_profile().getBirthday()*1000, System.currentTimeMillis());
			 holder.user_age.setText(strAge);
		}
		 if (list.get(position).getActor().getProfile()!=null) {
			 holder.user_address.setText(list.get(position).getActor().getProfile().getRegion());
		 }
		 if (list.get(position).getPost()!=null) {
			 if (list.get(position).getPost().getGroup()!=null) {
				 holder.group_name.setText(list.get(position).getPost().getGroup().getGroup_name());
			}
			
			 holder.topic_reanser_name.setText(list.get(position).getPost().getPost_actor_display_name());
			 holder.topic_reanser_content.setText(list.get(position).getPost().getMessage());
		}
		return convertView;
	}
	class ViewHolder {
		 AsyncImageView user_head ;
		 TextView  user_name,user_time,user_grade,
		 user_age,user_address,topic_reanser_name,
		 reply_count,group_name,topic_reanser_content;
		 Button user_result ,user_tool_but;
	}

}
